#pragma once
#include "windows.h"
#include "vector"
#include "list"
#include "map"
using namespace std;

class CGameObject
{
public:
	enum GameObjectType
	{
		GOT_NULL,
		GOT_Display,
		GOT_Texture,
		GOT_File,
		GOT_Sound,		
	};

private:
	int m_iID;

protected:
	GameObjectType m_eObjectType;	

private:
	static int m_iNextID;
	static int m_iObjectTotalNum;
	static map<int,CGameObject*> m_apkObjectInfo;

public:
	CGameObject()
	{
		m_eObjectType = GOT_NULL;

		m_iObjectTotalNum++;
		m_iNextID++;
		m_iID = m_iNextID;

		m_apkObjectInfo[m_iID] = this;
	}
	~CGameObject()
	{
		m_iObjectTotalNum--;
		m_apkObjectInfo[m_iID] = NULL;
		m_iID = 0;
	}

	int GetObjectID() const
	{
		return m_iID;
	}

	static int GetTotalObjectNum()
	{
		return m_iObjectTotalNum;
	}

	static const CGameObject* GetObjectByID(int iID)
	{
		if (iID <= 0)
		{
			return NULL;
		}

		if (m_apkObjectInfo.find(iID) == m_apkObjectInfo.end())
		{
			return NULL;
		}

		return m_apkObjectInfo[iID];
	}

	GameObjectType GetObjectType() const
	{
		return m_eObjectType;
	}

	virtual void AddRef() = NULL;
};

class CDisplayObject : public CGameObject
{
protected:
	DWORD m_dwColor;
	BYTE m_byAlpha;
	int m_iAbsX;
	int m_iAbsY;
	DWORD m_dwWidth;
	DWORD m_dwHeight;

public:
	CDisplayObject()
	{
		m_eObjectType = GOT_Display;

		m_dwColor = 0xFFFFFFFF;
		m_byAlpha = 255;
		m_iAbsX = m_iAbsY = 0;
		m_dwWidth = 0;
		m_dwHeight = 0;
	}
	~CDisplayObject()
	{

	}

	void AddRef()
	{
		return;
	}

	void SetColor(DWORD dwColor)
	{
		m_dwColor = dwColor;
	}

	int GetColor() const
	{
		return m_dwColor;
	}

	void SetAlpha(BYTE byAlpha)
	{
		m_byAlpha = byAlpha;
	}

	BYTE GetAlpha() const
	{
		return m_byAlpha;
	}

	void SetPos(int iX,int iY)
	{
		m_iAbsX = iX;
		m_iAbsY = iY;
	}

	void SetPosX(int iX)
	{
		m_iAbsX = iX;
	}

	void SetPosY(int iY)
	{
		m_iAbsY = iY;
	}

	int GetPosX() const
	{
		return m_iAbsX;
	}

	int GetPosY() const
	{
		return m_iAbsY;
	}

	void SetWidth(DWORD dwWidth)
	{
		m_dwWidth = dwWidth;
	}

	void SetHeight(DWORD dwHeight)
	{
		m_dwHeight = dwHeight;
	}

	DWORD GetWidth() const
	{
		return m_dwWidth;
	}

	DWORD GetHeight() const
	{
		return m_dwHeight;
	}

	bool IsMouseOn(int iX,int iY)
	{
		POINT kPt = {iX,iY};
		RECT kRect = {0,0,0,0};
		kRect.left = m_iAbsX;
		kRect.right = m_iAbsX + m_dwWidth;
		kRect.top = m_iAbsY;
		kRect.bottom = m_iAbsY + m_dwHeight;

		if (PtInRect(&kRect,kPt))
		{
			return true;
		}

		return false;
	}

	virtual void Draw()
	{
		return;
	}
};

class CGameUIObject : public CDisplayObject
{
protected:
	string m_kName;
	int m_iX;
	int m_iY;

public:
	CGameUIObject()
	{
		m_kName = "";
		m_iX = 0;
		m_iY = 0;
	}
	virtual ~CGameUIObject()
	{

	}

	const string& GetName() const
	{
		return m_kName;
	}

	void SetName(const string& rkName)
	{
		m_kName = rkName;
	}

	void SetX(int iX)
	{
		m_iX = iX;
	}

	void SetY(int iY)
	{
		m_iY = iY;
	}

	int GetX() const
	{
		return m_iX;
	}

	int GetY() const
	{
		return m_iY;
	}

	virtual void Update()
	{
		return;
	}

	virtual bool OnLeftBtnDown(int iX,int iY)
	{
		return false;
	}

	virtual bool OnLeftBtnUp(int iX,int iY)
	{
		return false;
	}

	virtual bool OnRightBtnDown(int iX,int iY)
	{
		return false;
	}

	virtual bool OnRightBtnUp(int iX,int iY)
	{
		return false;
	}

	virtual bool OnLeftBtnDbClick(int iX,int iY)
	{
		return false;
	}

	virtual bool OnRightBtnDbClick(int iX,int iY)
	{
		return false;
	}

	virtual bool OnMiddleBtnRollUp(int iStep)
	{
		return false;
	}

	virtual bool OnMiddleBtnRollDown(int iStep)
	{
		return false;
	}

	virtual bool OnMiddleBtnDown(int iX,int iY)
	{
		return false;
	}

	virtual bool OnMiddleBtnDbClick(int iX,int iY)
	{
		return false;
	}

	virtual bool OnMouseMove(int iX,int iY)
	{
		return false;
	}

	virtual void OnMouseMoveIn()
	{
		return;
	}

	virtual void OnMouseMoveOut()
	{
		return;
	}

	virtual bool OnKeyDown(BYTE byKey,bool bState)
	{
		return false;
	}

	virtual bool OnKeyUp(BYTE byKey,bool bState)
	{
		return false;
	}
};